package com.chuji.crmcj.adapter;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.chuji.crmcj.R;
import com.chuji.crmcj.bean.FullPayment;
import com.chuji.crmcj.utils.UIUtils;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * Created by Administrator on 2016/3/2.
 */
public class FullPaymentAdapter extends BaseAdapter {

    private Context mContext;
    private ListView mLvFullPay;
    private FullPayment fullPayment;

    public FullPaymentAdapter(Context mContext, ListView mLvFullPay, FullPayment fullPayment) {
        this.mContext = mContext;
        this.mLvFullPay = mLvFullPay;
        this.fullPayment = fullPayment;
    }

    @Override
    public int getCount() {
        return fullPayment.getApiParamObj().size();
    }

    @Override
    public Object getItem(int i) {
        return fullPayment.getApiParamObj().get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    private ViewHolder holder;

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = view.inflate(UIUtils.getContext(), R.layout.item_full_pay_car, null);
            holder = new ViewHolder();

            holder.mCustomerName = (TextView) view.findViewById(R.id.tv_customerName);
            holder.mPhoneNumber = (TextView) view.findViewById(R.id.tv_phoneNumber);
            holder.mCarModel = (TextView) view.findViewById(R.id.tv_carModel);
            holder.mCarModelLabel = (TextView) view.findViewById(R.id.tv_carModelLabel);
            holder.mSalesName = (TextView) view.findViewById(R.id.tv_salesName);
            holder.mDealDate = (TextView) view.findViewById(R.id.tv_dealDate);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
        //当前日期
        long time = System.currentTimeMillis();
        String currentDate = dateFormat.format(new Date(time));
        Date createDate = new Date(fullPayment.getApiParamObj().get(i).getCreateTime());
        String createDateStr = dateFormat.format(createDate);
        ImageView mNew = (ImageView) view.findViewById(R.id.img_new);
        if (currentDate.equals(createDateStr)) {
            mNew.setImageResource(R.drawable.weiduxiaoxi);
        } else {
            ColorDrawable cd = new ColorDrawable(0x00000000);
            cd.setAlpha(0);
            mNew.setImageDrawable(cd);
        }

        holder.mCustomerName.setText(fullPayment.getApiParamObj().get(i).getUserName() + "    ");
        holder.mPhoneNumber.setText(fullPayment.getApiParamObj().get(i).getCustormerTel());
        holder.mCarModel.setText(fullPayment.getApiParamObj().get(i).getCarModel());
        holder.mCarModelLabel.setText("成交车型");
        holder.mSalesName.setText(fullPayment.getApiParamObj().get(i).getSaleName());
        holder.mDealDate.setText(createDateStr);

        return view;
    }

    static class ViewHolder {
        private TextView mCustomerName;
        private TextView mPhoneNumber;
        private TextView mCarModel;
        private TextView mCarModelLabel;
        private TextView mSalesName;
        private TextView mDealDate;
    }
}
